package com.SMP.service.class_room;


import java.util.Date;
import java.util.List;
import com.SMP.dao.NewsMapper;
import com.SMP.model.News;
import com.SMP.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NewsService {
    /**
     * @author GJ
     * */
    @Autowired
    NewsMapper newsMapper;
    /**
     * @author GJ
    //	 * @param 查询所有新闻
     * */
    public List<News>selAllNews(){
        List<News> list=newsMapper.selectByExample(null);
        return list;
    }
/**
 * @author GJ
//	 * @param 添加新闻
 * */
    public int addNews(News news){
        String id = Utils.getsUUID();
        news.setId(id);
       // Calendar calendar = Calendar.getInstance();
      //  SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
        //String a =  dateFormat.format(calendar.getTime());
//        System.out.println(dateFormat.format(new Date()));// new Date()为获取当前系统时间
//        Date date = null;
//
//       Date date = null;
//        try {
//            date = dateFormat.parse( dateFormat.format(new Date()));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
     // news.setInputTime(date);
        news.setReleaseTime(new Date());
        return newsMapper.insert(news);
    }
    /**
     * @author GJ
    //	 * @param 修改新闻
     * */
    public int updNews(News news){
        news.setReleaseTime(new Date());
        return newsMapper.updateByPrimaryKey(news);
    }
    /**
     * @author GJ
    //	 * @param 删除新闻（假删）
     * */
    public int delNewsF(String id){
        News news=newsMapper.selectByPrimaryKey(id);
        news.setStandby1("2");
        return newsMapper.updateByPrimaryKey(news);
    }
    public News selectNewsId(String id) {
        return  newsMapper.selectByPrimaryKey(id);
    }

    //根据标题查询
    public List<News> NewsTitle(String title) {
        List<News> list=newsMapper.selectByTitle(title);
        return list;
    }
    //根据名字查询
    public List<News> NewsReleasePeople(String releasePeople) {
        List<News> list=newsMapper.selectByReleasePeople(releasePeople);
        return list;
    }
    //根据发布状态查询
    public List<News> NewsReleaseState(String releaseState) {
        List<News> list=newsMapper.selectByReleaseState(releaseState);
        return list;
    }

    public List<News> NewsType(String newsType) {
        List<News> list=newsMapper.selectByNewsType(newsType);
        return list;
    }

    public List<News> typeSelectAllNews() {
        List<News> list=newsMapper.TypeSelectByExample();
        return list;
    }

    public int updReleaseState(News news) {
        news.setReleaseState("2");
        return newsMapper.updateByReleaseState(news);
    }

    public int updReleaseState1(News news) {
        news.setReleaseState("3");
        return newsMapper.updateByReleaseState(news);
    }

    public List<News> ReleaseTimeNews(String releaseTime) {
        System.out.print(releaseTime);
        List<News> list=newsMapper.selectByReleaseTime(releaseTime);
        System.out.print(list);
        return list;
    }

}

